algalcommand.io
Class ScheduleKeeper

java.lang.Object
  extended by algalcommand.io.ScheduleKeeper
All Implemented Interfaces:
java.lang.Runnable

public class ScheduleKeeper
extends java.lang.Object
implements java.lang.Runnable

This class is used to manipulate an object based on a schedule. It assumes that the title for each column is equivalent to the name of the method to which the (interpolated) values apply.

This class uses a thread to periodically update the variables.


Constructor Summary
ScheduleKeeper()
          default constructor, you must use createSchedule(), setTarget(), and setUpdatePeriodInMinutes() before using start()
ScheduleKeeper(java.lang.Object target, java.io.File schedule, double minutes)
          Initializes with the given targets and schedule
 
Method Summary
 void abort()
          Stops reading the schedule
 void createSchedule(java.io.File src)
          Reads a file and initializes a schedule object from it
 java.lang.Object getTarget()
           
 long getUpdatePeriod()
           
static void main(java.lang.String[] args)
           
 void run()
          deriodically updates the target, sleeping in between.
 void setTarget(java.lang.Object obj)
          Sets the object to be updated periodically from the schedule
 void setUpdatePeriodInMinutes(double minutes)
          Sets the update period
 void setUpdatePeriodInSeconds(double seconds)
          Sets the update period
 void start()
          Starts updating the target from the schedule
 void update()
          Interpolates the schedule and then updates the target by invoking the methods named in the titles of the schedule file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScheduleKeeper

public ScheduleKeeper()
default constructor, you must use createSchedule(), setTarget(), and setUpdatePeriodInMinutes() before using start()


ScheduleKeeper

public ScheduleKeeper(java.lang.Object target,
                      java.io.File schedule,
                      double minutes)
               throws java.io.FileNotFoundException,
                      java.io.IOException
Initializes with the given targets and schedule

Parameters:
target - The object to be periodically modified
schedule - A schedule file with coulmns whose labels correspond to methods in the target object that take a double as a parameter.
minutes - The update period, in minutes
Throws:
java.io.FileNotFoundException - Thrown if schedule does not exist
java.io.IOException - Thrown if schedule can not be read
Method Detail

update

public void update()
Interpolates the schedule and then updates the target by invoking the methods named in the titles of the schedule file


createSchedule

public void createSchedule(java.io.File src)
                    throws java.io.FileNotFoundException,
                           java.io.IOException
Reads a file and initializes a schedule object from it

Parameters:
src - File that holds schedule data
Throws:
java.io.FileNotFoundException
java.io.IOException

start

public void start()
Starts updating the target from the schedule


abort

public void abort()
Stops reading the schedule


setTarget

public void setTarget(java.lang.Object obj)
Sets the object to be updated periodically from the schedule

Parameters:
obj - The object to be manipulated. It should have public methods that take a single double as the parameter and whose names are used as the titles in the schedule file

getTarget

public java.lang.Object getTarget()

getUpdatePeriod

public long getUpdatePeriod()
Returns:
The time between updates, in milliseconds

setUpdatePeriodInMinutes

public void setUpdatePeriodInMinutes(double minutes)
Sets the update period

Parameters:
minutes -

setUpdatePeriodInSeconds

public void setUpdatePeriodInSeconds(double seconds)
Sets the update period

Parameters:
seconds -

run

public void run()
deriodically updates the target, sleeping in between. Use abort() to stop.

Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)